package org.bai.miaoshaproject.controller;

import lombok.extern.slf4j.Slf4j;
import org.bai.miaoshaproject.dao.UserDOMapper;
import org.bai.miaoshaproject.dataobject.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName TestController
 *
 * @author Bai
 * @version 1.0
 * @date 2019/5/26 0026 下午 22:06
 **/
@Slf4j
@Controller
@RequestMapping(value = "/test")
public class TestController {

    private final UserDOMapper userDOMapper;

    @Autowired
    public TestController(UserDOMapper userDOMapper) {
        this.userDOMapper = userDOMapper;
    }

    @GetMapping(value = "/{id}")
    public @ResponseBody String getUser(@PathVariable(value = "id") Integer id){
        log.info("传入参数： " + id);
        UserDO userDO = userDOMapper.selectByPrimaryKey(id);
        if(userDO == null){
            return "用户对象不存在！";
        } else {
            return userDO.getName();
        }
    }
}
